// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-6 19:15:46
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Sql_and_java_map.java

package com.creawor.generator;

import java.io.PrintStream;

// Referenced classes of package com.creawor.generator:
//            SqlQueryBean

public class Sql_and_java_map
{

    public Sql_and_java_map(String table_name1)
    {
        table_name = "";
        clob_blob_add_code = "\n";
        table_name = table_name1;
    }

    public String po2vo_Copy()
    {
        String str_tmp = "";
        String str_field = "";
        try
        {
            SqlQueryBean qb = new SqlQueryBean();
            qb.connect();
            qb.SQLstr = (new StringBuilder("select * from ")).append(table_name).append(" where 1=2").toString();
            qb.executeQuery();
            for(int i = 1; i <= qb.getColumnCount(); i++)
            {
               // System.out.println(qb.getJavaType(i));
                str_field = qb.getFieldName(i);
                if(qb.getJavaType(i).indexOf("String") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("());\n").toString();
                if(qb.getJavaType(i).equals("long"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("    \te.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).equals("int"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("\t    e.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).equals("short"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("\t    e.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).equals("double"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf((").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("    \te.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).equals("float"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("( String.valueOf(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("    \te.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).indexOf("BigDecimal") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("\t    e.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).indexOf("Date") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(com.creawor.km.util.DateUtil.getStr(").append("po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(),\"yyyy-MM-dd\"));\n").append("  }catch (Exception e) {\n").append("\t    e.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).equals("boolean"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("    vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(String.valueOf(").append("po.is").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n").append("\t   e.printStackTrace();\n").append("  }\n").toString();
                if(qb.getJavaType(i).indexOf("Clob") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("     java.sql.Clob clob=po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("();\n").append("\tif (clob != null) {\n").append("      String b1 = clob.getSubString(1, (int) clob.length());\n").append("      vo.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(b1);\n   }\n").append("  }catch (Exception e) {\n").append("     e.printStackTrace();\n").append("  }\n").toString();
            }

            qb.disconnect();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        //System.out.println((new StringBuilder("\n")).append(str_tmp).toString());
        return str_tmp;
    }

    public String vo2po_Copy()
    {
        String str_tmp = "";
        String str_field = "";
        try
        {
            SqlQueryBean qb = new SqlQueryBean();
            qb.connect();
            qb.SQLstr = (new StringBuilder("select * from ")).append(table_name).append(" where 1=2").toString();
            qb.executeQuery();
            for(int i = 1; i <= qb.getColumnCount(); i++)
            {
                str_field = qb.getFieldName(i);
               // System.out.println((new StringBuilder("\n***********\n")).append(str_field).append("===").append(qb.getJavaType(i)).toString());
                if(qb.getJavaType(i).indexOf("String") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("());\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).equals("long"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(Long.parseLong(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).equals("int"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("    po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(java.lang.Integer.parseInt(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).equals("short"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("    po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(java.lang.Short.parseShort(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).equals("double"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("    po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(java.lang.Double.parseDouble(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append(" }catch (Exception e) {\n   e.printStackTrace();\n }\n").toString();
                if(qb.getJavaType(i).equals("float"))
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(" try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(java.lang.Float.parseFloat(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append(" }catch (Exception e) {\n   e.printStackTrace();\n }\n").toString();
                if(qb.getJavaType(i).indexOf("BigDecimal") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(" try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(java.lang.Float.parseFloat(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()));\n").append(" }catch (Exception e) {\n   e.printStackTrace();\n }\n").toString();
                if(qb.getJavaType(i).indexOf("Date") >= 0 || qb.getFieldTypeStr(i).toLowerCase().indexOf("date") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\n  try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(com.creawor.km.util.DateUtil.getDate(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(),\"yyyy-MM-dd\"));\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).indexOf("boolean") >= 0)
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(new Boolean(").append("vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()).booleanValue());\n").append("  }catch (Exception e) {\ne.printStackTrace();\n  }\n").toString();
                if(qb.getJavaType(i).indexOf("Clob") >= 0)
                {
                    str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("  try{\n").append("   po.set").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("(Hibernate.createClob(\" \"));\n").append("  }catch (Exception e) {\n   e.printStackTrace();\n  }\n").toString();
                    if(clob_blob_add_code.trim().length() < 10)
                        clob_blob_add_code = (new StringBuilder(String.valueOf(clob_blob_add_code))).append("   CLOB clob;\n").append("   java.io.Writer pw;\n").toString();
                    clob_blob_add_code = (new StringBuilder(String.valueOf(clob_blob_add_code))).append("\n   session.flush();\n").append("// Lock the relative row\n").append("   session.refresh(po, LockMode.UPGRADE);\n\n").append("   clob = (CLOB) po.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("();\n").append("   pw = clob.getCharacterOutputStream();\n").append("\n// Write the CLOB value into table\n").append("   pw.write(vo.get").append(str_field.substring(0, 1).toUpperCase()).append(str_field.substring(1).toLowerCase()).append("()); \n").append("   pw.close();\n\n").toString();
                }
            }

            qb.disconnect();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
       // System.out.println((new StringBuilder("\n")).append(str_tmp).toString());
        return str_tmp;
    }

    String table_name;
    String clob_blob_add_code;
}